<template>
	<view class="content">
		<view class="login_con">
			<view class="title">{{$t('welcome')}}</view>
			<view class="form">
				<view class="con">
					<label>{{$t('accounts')}}</label>
					<u-input v-model="account" :placeholder="$t('accounts_alert')" border="none"
						fontSize="30rpx"></u-input>
				</view>
				<view class="con">
					<label>{{$t('password')}}</label>
					<u-input v-model="password" password :placeholder="$t('password_alert')" border="none"
						fontSize="30rpx"></u-input>
				</view>
			</view>
			<view class="code">
				<!-- <text>验证码登录</text> -->
				<text @click="funHref('/pages/register/index')">{{$t('accounts_reg')}}</text>
			</view>
			<button @click="funLogin">{{$t('login')}}</button>
			<view class="agreement">
				<checkbox :checked="isRead" color="#f86e47" @click="funRead"></checkbox>
				<view>
					{{$t('login_agree')}}
					<text @click="funHref('/pages/content/agentNotes')">{{$t('service_agreement')}}</text>
					{{$t('gentle')}}
					<text @click="funHref('/pages/content/agentAgreement')">{{$t('privacy_policy')}}</text>
				</view>
			</view>
		</view>
		<!--刷新-->
		<view class='loadind_con' v-if="isLoading">
			<view class="loading">
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLoading: false, //是否正在加载
				isRead: false, //是否阅读
				account: '',
				password: ''
			}
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t('login')
			})
		},
		onLoad() {

		},
		methods: {
			//点击登录
			funLogin() {
				var _this = this;

				//判断
				if (_this.fun_validate(_this.account == '', "请输入帐号") ||
					_this.fun_validate(_this.password == '', "请输入密码") ||
					_this.fun_validate(_this.isRead == false, "请阅读协议并勾选")) {
					return;
				}

				_this.isLoading = true;
				_this.fun_request("/Api/Member/Login", {
					account: _this.account,
					password: _this.password
				}, function(res) {
					_this.fun_showToast(res.msg);

					//token
					uni.setStorageSync("token", res.token);
					uni.setStorageSync("member", res.data);

					//获取登录信息
					uni.$emit('load_getUserInfo');
					//更新购物车
					uni.$emit('load_getCart');
					//聊天内容
					uni.$emit('load_getChatroom');

					uni.navigateBack();
				}, function(res) {
					_this.fun_showToast(res.msg);
					_this.isLoading = false;
				});
			},
			//阅读
			funRead() {
				this.isRead = this.isRead ? false : true;
			},
			//跳转
			funHref: function(url) {
				if (url == 'none')
					this.fun_showToast("功能完善中...");
				else
					this.fun_navigateTo(url);
			},
		}
	}
</script>

<style lang="scss">
	.login_con {
		padding: 100rpx 5% 50rpx;

		.title {
			font-size: 36rpx;
			font-weight: bold;
		}

		.form {
			margin-top: 80rpx;

			.con {
				display: flex;
				flex-direction: row;
				align-items: center;
				padding: 25rpx 0;
				border-bottom: 1rpx solid #f0f0f0;

				label {
					font-size: 30rpx;
					margin-right: 30rpx;
					width: 80rpx;
				}
			}
		}

		.code {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			color: #F85F69;
			font-size: 28rpx;
			font-weight: bold;
			margin-top: 40rpx;
		}

		button {
			background: linear-gradient(to right, #F85F69, #ff6c45) !important;
			color: #fff;
			font-size: 30rpx;
			height: 90rpx;
			line-height: 90rpx;
			margin-top: 50rpx;
			border-radius: 50rpx;
		}

		.agreement {
			display: flex;
			align-items: center;
			margin-top: 40rpx;
			font-size: 30rpx;
			color: #666;

			checkbox {
				transform: scale(0.8);
			}

			view {

				text {
					color: #F85F69;
				}
			}
		}
	}
</style>